/*!
 * jQuery miniZoomPan 1.0
 * 2009 Gian Carlo Mingati
 * Version: 1.0 (18-JUNE-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Requires:
 * jQuery v1.3.2 or later
 * 
 */
jQuery.fn.miniZoomPan = function (settings) {
    settings = jQuery.extend({
        sW:10, // small image width
        sH:10, // small image height
        lW:20, // large image width
        lH:20 // large image height
    }, settings);

    return this.each(function () {
        var div = jQuery(this);
        div.css({width:settings.sW, height:settings.sH});
        var ig = div.children('img');
        ig.css({position:"relative"});
        jQuery(window).bind("load", function () {
            ig.width(settings.sW);
            ig.height(settings.sH);
        });
        div.css({overflow:"hidden"});
        ig.css("background", ig.attr('color'));

        div.mousemove(function (e) {
            var divWidth = div.width();
            var divHeight = div.height();
            var igW = ig.width();
            var igH = ig.height();
            var dOs = div.offset();
            var leftPan = (e.pageX - dOs.left) * (divWidth - igW) / (divWidth + 2);
            var topPan = (e.pageY - dOs.top) * (divHeight - igH) / (divHeight + 2);
            ig.css({left:leftPan, top:topPan});
        });

        div.hover(
            function () {
                ig.css({ width:settings.lW, height:settings.lH});
            },
            function () {
                ig.css({left:"0", top:"0", width:settings.sW, height:settings.sH});
            }
        );
    });
};